package com.orion.multi;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.nio.ByteBuffer;
import java.util.List;

/**
 * @author Administrator
 * @date 2021/3/15
 */
//extends ReplayingDecoder
public class ByteToLongHandler2 extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("ByteToLongHandler2的decode被调用了,out的size="+out.size());
        if (in.readableBytes()>= 8) {
            Long result = in.readLong();
            out.add(result);
        }
        //out.add(in.readLong());
    }

    public static void main(String[] args) {
       ByteBuffer buffer = ByteBuffer.allocate(8);
       String a = "11111111";
        buffer.put(a.getBytes(), 0, a.getBytes().length);
        buffer.flip();//need flip
        System.out.println(buffer.getLong());
    }
}
